package sealte.hvpms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sealte.hvpms.dao.AdminDAO;
import sealte.hvpms.dao.impl.AdminDAOImpl;
import sealte.hvpms.pojo.Admin;

public class AdminChangeLevel extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		String aid = (String)request.getParameter("id");
		String level = (String)request.getParameter("level");
		Admin admin = (Admin)request.getSession().getAttribute("admin");
		PrintWriter out = response.getWriter();
		
		if(admin!=null){
			if(aid!=null&&!aid.equals("")&&level!=null&&!level.equals("")){
				String message = "";
				AdminDAO ab = new AdminDAOImpl();
				boolean flag = ab.modifyLevel(Integer.parseInt(aid), level.equals("a")?"b":"a");
				if(flag){
					message = "ID为"+aid+"的管理员的权限修改成功";
				}else{
					message = "ID为"+aid+"的管理员的权限修改失败！！";
				}
				request.setAttribute("message_acl", message);
				request.getRequestDispatcher("hvpms_admin/admin_management.jsp").forward(request, response);
			}else{
				out.println("系统错误！");
			}
		}else{
			out.println("谢绝跨路径访问！");
		}
	}
}
